home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / lang / amigatalk.lha / intuition / IFF.st < prev    next >
Text File  |  2003-11-28  |  9KB  |  332 lines

  1. " ----------------------------------------------------------------------- "
  2. " The BasicIFF Class interfaces AmigaTalk to the iffparse.library.  See   "
  3. " class IDNumbers in IFFConstants.st file for valid ID numbers that       "
  4. " identify valid IFF chunks that IFF files & Objects contain.             "
  5. ""
  6. "    EXAMPLE:  16r424F4459 is 'BODY'                                      "
  7. ""
  8. " You should have access to the documentation for iffparse.library (or    "
  9. " wait for me to write some examples of how to use this Class ;).  I'm    "
  10. " NOT going to re-hash the IFF documentation for iffparse.library.  The   "
  11. " Help directory is getting complicated as it is.                         "
  12. " ----------------------------------------------------------------------- "
  13.  
  14. Class BasicIFF :Object ! private !
  15. [
  16.    closeIFF
  17.  
  18.       <primitive 240 0 0 private>.
  19.       
  20.       <primitive 250 5 0 private>.
  21.       
  22.       ^ nil
  23. |
  24.    openIFF: iffFileName type: fileType mode: mode ! chk !
  25.  
  26.       " fileType here means: 0 for a file, & 1 for a clipboard. 
  27.       * mode is either #IFFF_READ, IFFF_WRITE or IFFF_RWBITS:
  28.       "
  29.       chk <- <primitive 240 0 1 iffFileName fileType mode>.
  30.  
  31.       (chk isNil)
  32.          ifTrue: ['Did NOT openIFF (nil returned!).' print.
  33.  
  34.                    ^ nil
  35.                  ].
  36.       
  37.       ^ private <- chk
  38. |
  39.    initIFFHook: hookObj flags: flags 
  40.  
  41.       <primitive 240 1 0 private hookObj flags>
  42. |
  43.    initIFFAsDOS
  44.  
  45.       <primitive 240 1 1 private>
  46. |
  47.    initIFFAsClip
  48.  
  49.       <primitive 240 1 2 private>
  50. |
  51.    closeClipboard
  52.  
  53.       <primitive 240 2 0 private>
  54. |
  55.    openClipboard: clipUnitNumber  " Range for clipUnitNumber is 0 to 255 "
  56.  
  57.       ^ <primitive 240 2 1 private clipUnitNumber>
  58. |
  59.    parseIFF: mode
  60.  
  61.       " Control modes for parseIFF method:
  62.       * #IFFPARSE_SCAN
  63.       * #IFFPARSE_STEP
  64.       * #IFFPARSE_RAWSTEP
  65.       "
  66.       ^ <primitive 240 2 2 private mode>
  67. |
  68.    readChunkBytes: byteArray size: numBytes
  69.  
  70.       ^ <primitive 240 2 3 private byteArray numBytes>
  71. |
  72.    readChunkRecords: byteArray size: numBytes number: numRecords
  73.  
  74.       ^ <primitive 240 2 4 private byteArray numBytes numRecords>
  75. |
  76.    writeChunkBytes: byteArray size: numBytes
  77.  
  78.       ^ <primitive 240 2 5 private byteArray numBytes>
  79. |
  80.    writeChunkRecords: byteArray size: numBytes number: numRecords
  81.  
  82.       ^ <primitive 240 2 6 private byteArray numBytes numRecords>
  83. |
  84.    stopChunk: type id: id
  85.  
  86.       " The most common types are: 
  87.       *   #ID_ILBM, #ID_FTXT, #ID_SMUS, #ID_8SVX, #ID_ANIM
  88.       *
  89.       * See IDNumbers Class in IFFConstants.st for id values.
  90.       "
  91.       ^ <primitive 240 2 7 private type id>
  92. |
  93.    stopChunksWith: propertyArray size: numPairs
  94.  
  95.       " Do a bunch of stopChunk settings at once.
  96.       *
  97.       * The propertyArray is constructed as follows:
  98.       * ele[1] <- type,     ele[2] <- id,
  99.       * ele[3] <- nextType, ele[4] <- nextid,
  100.       * ...
  101.       "
  102.       ^ <primitive 240 2 16 private propertyArray numPairs>
  103. |
  104.    currentChunk
  105.  
  106.       ^ <primitive 240 2 8 private>
  107. |
  108.    propertyChunk: type id: id
  109.  
  110.       ^ <primitive 240 2 9 private type id>
  111. |
  112.    propertyChunksWith: propertyArray size: numPairs
  113.  
  114.       " Do a bunch of propertyChunk settings at once.
  115.       *
  116.       * The propertyArray is constructed as follows:
  117.       * ele[1] <- type,     ele[2] <- id,
  118.       * ele[3] <- nextType, ele[4] <- nextid,
  119.       * ...
  120.       "
  121.       ^ <primitive 240 2 17 private propertyArray numPairs>
  122. |
  123.    findProperty: type id: id
  124.  
  125.       ^ <primitive 240 2 10 private type id>
  126. |
  127.    collectionChunk: type id: id
  128.  
  129.       ^ <primitive 240 2 11 private type id>
  130. |
  131.    collectionChunksWith: propertyArray size: numPairs
  132.  
  133.       " Do a bunch of collectionChunk settings at once.
  134.       * The propertyArray is constructed as follows:
  135.       *
  136.       * ele[1] <- type,     ele[2] <- id,
  137.       * ele[3] <- nextType, ele[4] <- nextid,
  138.       * ...
  139.       "
  140.       ^ <primitive 240 2 18 private propertyArray numPairs>
  141. |
  142.    findCollection: type id: id
  143.  
  144.       ^ <primitive 240 2 12 private type id>
  145. |
  146.    stopOnExit: type id: id
  147.  
  148.       ^ <primitive 240 2 13 private type id>
  149. |
  150.    addEntryHandlerHook: hookObj for: anObject type: type id: id position: pos
  151.  
  152.       ^ <primitive 240 2 14 private hookObj anObject type id pos>
  153. |
  154.    addExitHandlerHook: hookObj for: anObject type: type id: id position: pos
  155.  
  156.       ^ <primitive 240 2 15 private hookObj anObject type id pos>
  157. |
  158.    pushChunk: type id: id size: size
  159.  
  160.       " size can also be #IFFSIZE_UNKNOWN if you dont know the size "
  161.       ^ <primitive 240 3 0 private type id size>
  162. |
  163.    popChunk
  164.  
  165.       ^ <primitive 240 3 1 private>
  166. |
  167.    parentChunk
  168.  
  169.       ^ <primitive 240 3 2 private>
  170. |
  171.    allocateLocalItem: ident type: type id: id size: dataSize
  172.  
  173.       ^ <primitive 240 4 0 private type id ident dataSize>
  174. |
  175.    getLocalItemData
  176.  
  177.       ^ <primitive 240 4 1 private>
  178. |
  179.    storeLocalItem: position
  180.  
  181.       ^ <primitive 240 4 2 private position>
  182. |
  183.    storeItemInContext
  184.  
  185.       <primitive 240 4 3 private>
  186. |
  187.    findPropertyContext
  188.  
  189.       ^ <primitive 240 4 4 private>
  190. |
  191.    findLocalItem: ident type: type id: id
  192.  
  193.       ^ <primitive 240 4 5 private type id ident>
  194. |
  195.    freeLocalItem
  196.  
  197.       <primitive 240 4 6 private>
  198. |
  199.    setLocalItemPurge: hookObj
  200.       <primitive 240 4 7 private hookObj>
  201. |
  202.    getErrorString: errorNumber
  203.  
  204.       ^ <primitive 240 5 errorNumber>
  205. |
  206.    idToString: identifier
  207.  
  208.       ^ <primitive 240 6 identifier>
  209. |
  210.    getPropertySize: propertyObject
  211.  
  212.       ^ <primitive 240 7 0 propertyObject>
  213. |
  214.    getPropertyData: propertyObject
  215.  
  216.       ^ <primitive 240 7 1 propertyObject>
  217. |
  218.    getCollectionSize: collectionObject
  219.  
  220.       ^ <primitive 240 8 0 collectionObject>
  221. |
  222.    getCollectionData: collectionObject
  223.  
  224.       ^ <primitive 240 8 1 collectionObject>
  225. ]
  226.  
  227. " ----------------------------------------------------------------------- "
  228. " The ExamineIFF Class allows the User to obtain various chunks from an   "
  229. " IFF file (NOT clipboards).                                              "
  230. " ----------------------------------------------------------------------- "
  231.  
  232. Class ExamineIFF :BasicIFF ! dataTypeTags ilbm rmode form body ftxt !
  233. [
  234.    initialize
  235.  
  236.       dataTypeTags <- DataTypeTags new.
  237.       body         <- dataTypeTags systemTag: #ID_BODY.
  238.       form         <- dataTypeTags systemTag: #ID_FORM.
  239.       ilbm         <- dataTypeTags systemTag: #ID_ILBM.
  240.       ftxt         <- dataTypeTags systemTag: #ID_FTXT.
  241.       rmode        <- dataTypeTags systemTag: #IFFF_READ.
  242.  
  243.       ^ self
  244. |
  245.    privateObtainChunk: chunkType from: fileName id: chunkID parent: pID ! iffObj chk rval !
  246.       
  247.       iffObj <- super openIFF: fileName type: 1 mode: rmode.
  248.       
  249.       iffObj initIFFAsDOS.
  250.       
  251.       chk <- iffObj propertyChunk: chunkType id: chunkID. " Look for this chunk "
  252.       
  253.       (chk ~= 0 or: [chk isNil])
  254.          ifTrue: [ (iffObj getErrorString: chk) print.
  255.  
  256.                    iffObj closeIFF.
  257.  
  258.                    ^ nil                 ].
  259.          
  260.       chk <- iffObj stopChunk: chunkType id: pID.
  261.  
  262.       (chk ~= 0 or: [chk isNil])
  263.          ifTrue: [ (iffObj getErrorString: chk) print.
  264.  
  265.                    iffObj closeIFF.
  266.  
  267.                    ^ nil                 ].
  268.  
  269.       chk <- iffObj parseIFF: (dataTypeTags systemTag: #IFFPARSE_SCAN).
  270.  
  271.       (chk ~= 0 or: [chk isNil])
  272.          ifTrue: [ (iffObj getErrorString: chk) print.
  273.  
  274.                    iffObj closeIFF.
  275.  
  276.                    ^ nil                 ].
  277.  
  278.       rval <- iffObj findProperty: chunkType id: chunkID.
  279.  
  280.       (rval isNil)
  281.          ifTrue: [ 'NO bitmap header found!' print.
  282.  
  283.                    iffObj closeIFF.
  284.  
  285.                    ^ nil                 ].
  286.          
  287.       iffObj closeIFF.
  288.  
  289.       ^ rval
  290. |
  291.    obtainBMHD: fileName ! bmhd !
  292.  
  293.       bmhd <- dataTypeTags systemTag: #ID_BMHD.
  294.       
  295.       ^ self privateObtainChunk: ilbm from: fileName id: bmhd parent: body
  296. |
  297.    obtainCMAP: fileName ! cmap !
  298.  
  299.       cmap <- dataTypeTags systemTag: #ID_CMAP.
  300.       
  301.       ^ self privateObtainChunk: ilbm from: fileName id: cmap parent: body
  302. |
  303.    obtainCAMG: fileName ! camg !
  304.  
  305.       camg <- dataTypeTags systemTag: #ID_CAMG.
  306.       
  307.       ^ self privateObtainChunk: ilbm from: fileName id: camg parent: body
  308. |
  309.    obtainPixelData: fileName
  310.  
  311.       ^ self privateObtainChunk: ilbm from: fileName id: body parent: form
  312. |
  313.    obtainCHRS: fileName ! chrs !
  314.  
  315.       chrs <- dataTypeTags systemTag: #ID_CHRS.
  316.       
  317.       ^ self privateObtainChunk: ftxt from: fileName id: chrs parent: form
  318. |
  319.    obtainVHDR: fileName ! vhdr svx8 !
  320.  
  321.       svx8 <- dataTypeTags systemTag: #ID_8SVX.
  322.       vhdr <- dataTypeTags systemTag: #ID_VHDR.
  323.       
  324.       ^ self privateObtainChunk: svx8 from: fileName id: vhdr parent: form
  325. |
  326.    obtainVoiceData: fileName ! svx8 !
  327.  
  328.       svx8 <- dataTypeTags systemTag: #ID_8SVX.
  329.       
  330.       ^ self privateObtainChunk: svx8 from: fileName id: body parent: form
  331. ]
  332.